package com.shengyuan.manage_os.old.ying.erpm;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.old.ying.erpm.data.MenuItem;
import com.shengyuan.manage_os.old.ying.erpm.layout.Workspace.OnViewChangedListener;
import com.shengyuan.manage_os.old.ying.erpm.tasks.Submit_System_Setting_Data_Task;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Message;

public class JiXieActivity extends WorkSpaceActivity implements OnViewChangedListener {

//	@Override
//	public List<MenuItem> LoadMenuListItems() {
//    	MenuItem item;
//    	List<MenuItem> list = new ArrayList<MenuItem>();
//    	Resources res =getResources();
//    	String[] city=res.getStringArray(R.array.main_menus_jx);
//    	for (int i = 0; i < city.length; i++) {
//    		item = new MenuItem();
//			item.title = city[i];
//			item.index = i;
//			list.add( item);
//		} 
//    	return list;
//	}
	@Override
	public List<MenuItem> LoadMenuListItems() {
    	MenuItem item; int k;
    	List<MenuItem> list = new ArrayList<MenuItem>();
    	Resources res =getResources();
    	String[] gc =  Submit_System_Setting_Data_Task.A_GONGCHENGMINGCHENG_GC ;//res.getStringArray(R.array.main_menus_gc);
    	if(gc==null) return null;
    	for (int i = 0; i < gc.length; i++) {
    			String  ShiShiContent ="", ShiShiTimeE="", GongYingShang="";
    			try {
    				ShiShiContent = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_GC.getJSONObject(i).getString("ShiShiContent");
    				ShiShiTimeE = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_GC.getJSONObject(i).getString("ShiShiTimeE");
    				GongYingShang = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_GC.getJSONObject(i).getString("GongYingShangJia");
				} catch (JSONException e) {
					e.printStackTrace();
				}

        		item = new MenuItem();
    			item.title = gc[i];
    			item.ShiShiTimeE = ShiShiTimeE;
    			item.ShiShiContent = ShiShiContent;
    			item.GongYingShang = GongYingShang;
    			item.index =  i;
    			list.add( item);	
		}
    	return list;
	}
	
    @Override
	public boolean IsAllow() {
		if (LoginActivity.pmUser.getLogOut() == false) {
			return LoginActivity.pmUser.Department.contains("机械运输部")
					|| LoginActivity.pmUser.JiaoSe.contains("超级管理员")
					|| LoginActivity.pmUser.JiaoSe.contains("总经理")
					|| LoginActivity.pmUser.JiaoSe.contains("副总经理")
					|| LoginActivity.pmUser.JiaoSe.contains("董事长");
		}else
			return false;
	}
	private Handler mHandler= new Handler(){

		@Override
		public void handleMessage(Message msg) {
			
			MenuItem item =(MenuItem) msg.obj;
			int index = item.index;
			String BaoDanLeiXing = "";
			try {
				Submit_System_Setting_Data_Task.mID = index;
				//表单类型
				BaoDanLeiXing = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_GC.getJSONObject(index).getString("BaoDanLeiXing");
				//实施结束时间
				String value = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_GC.getJSONObject(index).getString("ShiShiTimeE");
				value = value.replace("\r","");
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				WorkSpaceActivity.ShiShiTimeE = formatter.parse(value);
				
				//项目列表
				String JieDuanName = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_GC.getJSONObject(index).getString("JieDuanName");
				String ProjectName  = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_GC.getJSONObject(index).getString("ProjectName"); 
				WorkSpaceActivity.ProjectName.put(ProjectName, JieDuanName);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			Intent intent = new Intent(); 
			if (BaoDanLeiXing.equals(getResources().getString(R.string.title_actual_form_baoyanghuizhi))) {
				intent.setClass( JiXieActivity.this , Actual_Form_BaoYangHuiZhi.class);
			}else if(BaoDanLeiXing.equals(getResources().getString(R.string.title_actual_form_jx_jixiejishi))) {
        	    WorkSpace_TaiBanActivity_JX.ButtonIndex = 0;
        	    intent.setClass(JiXieActivity.this, WorkSpace_TaiBanActivity_JX.class);
        	    intent.putExtra("VerticalSpacing", 20);
			}else if(BaoDanLeiXing.equals(getResources().getString(R.string.title_actual_form_jx_jixiejiayou))) {
        	    intent.setClass(JiXieActivity.this, Actual_Form_JiXie_CheJiaYou.class);
			}else if(BaoDanLeiXing.equals(getResources().getString(R.string.title_actual_form_jx_shiwuziyuanruku))) {
        	    intent.setClass(JiXieActivity.this, Actual_JX_RuKuDan.class);
			}else if(BaoDanLeiXing.equals(getResources().getString(R.string.title_actual_form_jx_shiwuziyuanchuku))) {
        	    intent.setClass(JiXieActivity.this, Actual_JX_ChuKuDan.class);
			}else if(BaoDanLeiXing.equals(getResources().getString(R.string.title_actual_form_jx_shiwuziyuanruku_huanquan))) {
        	    intent.setClass(JiXieActivity.this, Actual_JX_RuKuDan_HuangQuan.class);
			}else if(BaoDanLeiXing.equals(getResources().getString(R.string.title_actual_form_jx_shiwuziyuanchuku_huanquan))) {
        	    intent.setClass(JiXieActivity.this, Actual_JX_ChuKuDan_HuangQuan.class);
			}else {
				return;
			}
//        	//intent.setClass( JiXieActivity.this , Actual_Form_JiXie_CheTiYou.class);
			startActivity(intent);
		}
	};
//	@Override
//	public void GetProjectDataList() {
//		Submit_System_Setting_Data_Task mSubmitTask = new Submit_System_Setting_Data_Task();
//		mSubmitTask.setListener(mTaskListener);
//		TaskParams params;
//		params = new TaskParams();
//		params.put(Submit_System_Setting_Data_Task.TYPENAME,Submit_System_Setting_Data_Task.T_GONGCHENGMINGCHENG_GC);
//		params.put(Submit_System_Setting_Data_Task.TYPECODE, LoginActivity.pmUser.UserName);
//		mSubmitTask.execute(params);
//	}
//	private Handler mHandler= new Handler(){
//
//		@Override
//		public void handleMessage(Message msg) {
//			BaseActivity.A_GONGCHENGMINGCHENG = Submit_System_Setting_Data_Task.A_GONGCHENGMINGCHENG_JX;
//			BaseActivity.J_GONGCHENGMINGCHENG = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_JX;
//			BaseActivity.A_GONGCHENGMINGCHENG_XIANGMU = Submit_System_Setting_Data_Task.A_GONGCHENGMINGCHENG_JX_XIANGMU;
//			BaseActivity.J_GONGCHENGMINGCHENG_XIANGMU = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_JX_XIANGMU;
//			
//			MenuItem item =(MenuItem) msg.obj;
//			int index = item.index;
//			String BaoDanLeiXing = "";
//			Submit_System_Setting_Data_Task.mID = index;
//				
//			Intent intent = new Intent();
//            switch (msg.arg1) {
//            case 0:
//        	    WorkSpace_TaiBanActivity_JX.ButtonIndex = msg.what;
//        	    intent.setClass(JiXieActivity.this, WorkSpace_TaiBanActivity_JX.class);
//        	    intent.putExtra("VerticalSpacing", 20);
//            	break;
//            case 1:
//            	intent.setClass( JiXieActivity.this , Actual_Form_BaoYangHuiZhi.class);
//            	break;
//            case 2: 
//            	//intent.setClass( JiXieActivity.this , Actual_Form_JiXie_CheTiYou.class);
//            	Utility.MessageBox("未完成");return;
//            case 3:
//            	intent.setClass( JiXieActivity.this , Actual_Form_JiXie_CheJiaYou.class);
//            	break;
//
//            case 4:
//            	intent.setClass( JiXieActivity.this , FinishedListActivity.class);
//            	break;
//            case 5:
//            	intent.setClass(JiXieActivity.this, Actual_GC_CaiGouDan.class);
//            	break;
////            case 7:
////            	intent.setClass(JiXieActivity.this, Actual_OA_ShouKuanDan.class);
////            	break;
////            case 8:        	    
////            	intent.setClass(JiXieActivity.this, Actual_OA_BaoXiaoDan.class);
////            	break;
//            }
//            startActivity(intent);
//		}
//    	
//    };


	@Override
	public Handler GetHandler() {
		return mHandler;
	}
}